APM.ConfigClusterController = Ember.Controller.extend({
	form: {
		ip:"",
		confType:"9"
	},    
	
	 checkFormValid: function(){
	   		var form = this.get("form");
	   		
	   		this.set("saveResult", null);

	   		if( form.ip == "" ){
	   			this.set("formTip", "请输入加入节点组IP!！");
	   			return false;
	   		}
	   		if(form.ip){
	   			var reg1=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
				if(!reg1.test(form.ip)){  
					   this.set("formTip", "您输入的IP地址非法，请重新输入!");
					   return false;
				} 
	   		}
	   		this.set("formTip", null);
	   		return true;
	   	},  
	 
	actions: {
		reset : function() {
			this.set("formTip", null);
			this.set("saveResult", null);
		},
		
		//对话框操作方法
		 openDialog: function(dioIndex){
            var dialog = Broada.getView("config_cluster_add");
            Broada.getView("config_cluster_add").openDialog();
        },
        
        closeDialog: function(){
           Broada.getView("config_cluster_add").closeDialog();
        },
        
		addCluster: function(){
			if( !this.checkFormValid() ){
				return;
			}
			alert("添加节点组");
			var ctrl = this;
			var form = this.get("form");

			ctrl.set("saveResult", null);
			
			this.store.ajax("POST", "configs/systemConfig", {
				ip: form.ip,
				confType:form.confType
			})
			.then(function(response){
				if(response.status=="success"){
					//todo: 保存成功逻辑
					ctrl.set("saveResult", "保存成功！");
				}
			}, function(){
				ctrl.set("saveResult", "保存出错");
			});
		},
		
		deleteCluster: function(){
			alert("删除节点组");
			var ctrl = this;
			var form = this.get("form");

			ctrl.set("saveResult", null);

			this.store.ajax("DELETE", "configs/systemConfig", {
				ip: form.ip
			}).then(function(response){
				if(response.status=="success"){
				//todo: 保存成功逻辑
				ctrl.set("saveResult", "删除成功！");
				}
			}, function(){
				ctrl.set("saveResult", "删除失败！");
			});
		}

	}
	
});